<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('入库审核')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>收货仓库：</label>
                                <input type="text" name="consigneeDept"/>
                                <input type="hidden" id="deptId" th:value="${@permission.getPrincipalProperty('deptId')}">

                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <!--<div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="goods:bill:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="goods:bill:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="goods:bill:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>-->
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('goods:bill:audit_bill')}]];
        var prefix = ctx + "goods/bill";
        var datas = [[${@dict.getType('bill_status')}]];
        var comboxList = [[${@dict.getType('bill_status')}]];
        var deptId = [[${@permission.getPrincipalProperty('deptId')}]];
        $(function() {
            var options = {
                url: prefix + "/list?deptId="+deptId,
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "入库管理",
                detailView: true,
                onExpandRow : function(index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                columns: [{
                    checkbox: true
                },
                {
                    field: 'billNo',
                    title: '发货单号'
                },
                {
                    field: 'quantity',
                    title: '数量'
                },
                {
                    field: 'totalPrice',
                    title: '总价'
                },
                {
                    field: 'deptId',
                    title: '收货仓库'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter:function (value, row, index) {
                        return $.table.selectDictLabel(comboxList, value);
                    }
                },
                {
                    field: 'remark',
                    title: ''
                },
                {
                    field: 'deptName',
                    title: '收货仓库'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        //var actions = [];return actions.join('');
                        // if(row.status=='2' || row.status==2){
                        //     return "1";//'<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="audit(\'' + row.billNo + '\',\'' + row.status + '\')"><i class="fa fa-edit"></i>入库</a> ';
                        // }else{
                        //     return '';
                        // }

                        var actions = [];
                        //新建状态下，才可以修改。
                        if(row.status==2){
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="audit(\'' + row.billNo + '\',\'' + row.status + '\')"><i class="fa fa-edit"></i>入库</a> ');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        initChildTable = function(index, row, $detail) {
            var prefixDownload=ctx + "common/download/resource?resource=";
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            var prefix = ctx + "goods/billHead";
            $(childTable).bootstrapTable({
                url: prefix + "/list",
                method: 'post',
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams : {
                    billNo: row.billNo
                },
                columns: [
                    {
                        field: 'styleNumber',
                        title: '款号'
                    },
                    {
                        field: 'imgPath',
                        title: '图片',
                        formatter: function(value, row, index) {
                            //console.log(row.imgPath)
                            if(row.imgPath==''||row.imgPath==null){
                                return '';
                            }else{
                                return $.table.imageView(prefixDownload+row.imgPath);
                            }
                        }
                    },
                    {
                        field: 'quantity',
                        title: '数量'
                    },
                    {
                        field: 'price',
                        title: '单价'
                    },
                    {
                        field: 'totalPrice',
                        title: '总价'
                    }
                ]
            });
        };


        //入库
        function audit(billNo,status){
            /*if(status==3){
                $.modal.msgError("不能重复入库");
                return;
            }*/
            $.modal.confirm("确认已经收到货物吗？", function() {
                var prefix = ctx + "goods/bill"
                var url=prefix+"/audit?billNo="+billNo+"&status=3";
                $.operate.save(url);
            });
        }
    </script>
</body>
</html>